# -*-coding:utf-8-*-
import numpy as np

"""
1.处理numPy二进制文件（带npy扩展名）
load()
save()
2.处理正常的文本文件
loadtxt()
savetxt()
"""
a = np.array([[1, 2, 3], [4, 5, 6]], dtype=float)

# np.save('out.npy', a)  # 生成out.npy
# np.load('out.npy')  # [[1. 2. 3.] [4. 5. 6.]]
# np.savetxt('out.txt', a)
# np.loadtxt('out.txt')  # [[1. 2. 3.] [4. 5. 6.]]

# 读取csv文件,dtype默认为float，usecols指定读取哪几列，unpack为True将拆分每一列返回ndarray元组
csv = np.loadtxt('test.csv', delimiter=',', usecols=(2, 3), skiprows=1, encoding='utf-8')
print(csv)  # [[147.  50.] [128.  83.] [103.  59.] [157.  76.] [100.  91.] [ 97.  43.]]
